package com.itheima.health.service.impl;

import com.itheima.health.common.MessageConst;
import com.itheima.health.dao.MemberDao;
import com.itheima.health.pojo.Member;
import com.itheima.health.service.MemberService;
import com.itheima.health.util.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class MemberServiceImpl implements MemberService {
    @Autowired
    private MemberDao memberDao;

    @Override
    public Member getone(String phoneNumber) {
        Member member= memberDao.getone(phoneNumber);
        return member;
    }

    @Override
    public void save(Member member) {
        memberDao.save(member);
    }

    @Override
    public List<Integer> countMember(List<String> months) {

        List<Integer> countMember = new ArrayList<>();

        for (String month : months) {
            // 每月的 第一天
            String firstDay= month+ MessageConst.MEI_GE_YUE_DI_YI_TIAN;
            //获取到 每月的 最后一天
            String lastDay= DateUtils.getLastDay(month);
            Long count = memberDao.countMember(firstDay,lastDay);
            countMember.add(count.intValue());
        }
        return countMember;
    }
}
